package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.DepartmentDao;
import com.ef.domain.Department;
import com.ef.service.DepartmentService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class DepartmentServiceImpl extends BaseServiceImpl implements
		DepartmentService {

	private DepartmentDao departmentDao;

	public void delete(Department entity) {
		entity.setStatus(StatusType.INVALID);
		departmentDao.update(entity);

	}

	public PaginationSupport<Department> findByExample(
			CustomExample<Department> example, int startIndex, int pageSize) {

		return departmentDao.findPageByExample(example, startIndex, pageSize);
	}

	public Department findById(Long id) {

		return departmentDao.findById(id);
	}

	public void saveOrUpdate(Department entity) {
		departmentDao.clear();
		departmentDao.saveOrUpdate(entity);

	}
	
	public List<Department> findAll(){
		DetachedCriteria criteria = DetachedCriteria.forClass(Department.class
				);
		criteria.add(Restrictions.eq("status", StatusType.VALID));
		return departmentDao.findAllByCriteria(criteria);
	}

	public DepartmentDao getDepartmentDao() {
		return departmentDao;
	}

	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

}
